package cn.jorian.framework.controller;

import cn.jorian.framework.entity.User;
import cn.jorian.framework.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/jpa")
public class JpaController {

    @Autowired
    private UserService userService;

    @PostMapping("/insertUser")
    public void saveUser() {
        User user = new User();
        user.setName("hutoa");
        user.setEmail("789@qq.com");
        user.setAge(18);
        userService.saveUser(user);
    }

    @GetMapping("/getUser")
    public List<User> getUser() {
        String mail = "789@qq.com";
        return userService.findByEmail(mail);
    }

    @GetMapping("/getPageUser")
    public Page<User> getPageUser() {
        return userService.findByAll();
    }

    @GetMapping("/getByAge")
    public List<User> getByAge(@RequestParam("age") Integer age) {
        return userService.getByAge(age);
    }
}
